/**
 * 统计对象
 */
var Statistics = {
};

$(function () {
    loadChart("","");
});

Statistics.search = function () {
    var beginTime = $("#beginTime").val();
    var endTime = $("#endTime").val();
    loadChart(beginTime,endTime);
};

Statistics.resetSearch = function () {
    $("#beginTime").val("");
    $("#endTime").val("");
    loadChart("","");
};

function loadChart(startTime,endTime) {
    var useAppChart = echarts.init(document.getElementById('use-app'));
    var playCountChart = echarts.init(document.getElementById('play-count'));
    var twoDateChart = echarts.init(document.getElementById('two-count'));
    useAppChart.showLoading();
    playCountChart.showLoading();
    twoDateChart.showLoading();
    $.get(Feng.ctxPath+'/statistics/useApp?beginTime='+startTime+"&endTime="+endTime).done(function (data) {
        useAppChart.hideLoading();
        useAppChart.setOption({
            title:{
                text:"app使用统计"
            },
            tooltip:{},
            legend:{
                data:['app使用统计']
            },
            xAxis:{
                data:data.days
            },
            yAxis:{},
            series:{
                name:'使用统计',
                type:'line',
                color: ['#73a373'],
                smooth:true,
                data:data.counts
            }
        });
    });
    $.get(Feng.ctxPath+'/statistics/playCount?beginTime='+startTime+"&endTime="+endTime).done(function (data) {
        playCountChart.hideLoading();
        playCountChart.setOption({
            title:{
                text:"播放量统计"
            },
            tooltip:{},
            legend:{
                data:['播放量统计']
            },
            xAxis:{
                data:data.days
            },
            yAxis:{},
            series:{
                name:'播放量统计',
                type:'line',
                color: ['#8dc1a9'],
                smooth:true,
                data:data.counts
            }
        });
    });
    $.get(Feng.ctxPath+'/statistics/twoDataCount?beginTime='+startTime+"&endTime="+endTime).done(function (data) {
        twoDateChart.hideLoading();
        twoDateChart.setOption({
            title:{
                text:"合并统计"
            },
            tooltip:{},
            legend:{
            },
            dataset:{
                source:[
                    ["日期"].concat(data.days),
                    ["使用量"].concat(data.useCounts),
                    ["播放量"].concat(data.playCounts)
                ]
            },
            xAxis:[
                {type: 'category', gridIndex: 0}
            ],
            yAxis:[
                {gridIndex: 0}
            ],
            series:[
                {type: 'line', smooth:true,seriesLayoutBy: 'row',color:['#759aa0']},
                {type: 'line', smooth:true,seriesLayoutBy: 'row',color:['#d48265']}
            ]
        });
    });
}